package com.ft.sso.secrityauthor2sso.config;

import com.ft.sso.secrityauthor2sso.extent.JwtExtentConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * @Author RenPu
 * @Date 2022/9/28 17:48
 * @Version 1.0
 * @Description: token存储在Jwt所需要的配置
 **/
@Configuration
public class JwtConfig {
    /**
     * 将连接工厂交给RedisTokenStore，进行将token存储到redis
     * @return
     */
    @Bean
    public TokenStore jwtTokenStore(){
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter jwtAccessTokenConverter =  new JwtAccessTokenConverter();
        //设置Jwt得盐值（密钥）
        jwtAccessTokenConverter.setSigningKey("123123");
        return jwtAccessTokenConverter;
    }


    /**
     * jwt增强器对象的孵化
     * @return
     */
    @Bean
    public JwtExtentConfig jwtExtentConfig(){
        return new JwtExtentConfig();
    }



}
